<%= form_for [:shop, @spu], html: { class: "card" } do |f| %>
  <div class="card-body">
    <h3 class="card-title">修改商品</h3>
    <div class="row">
      <%= render 'shop/shared/error_messages', target: @spu %>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="form-group">
          <label class="form-label">名字</label>
          <%= f.text_field :name, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-12">
        <div class="form-group">
          <label class="form-label">描述<small>（此值用于分享到第三方的介绍）</small></label>
          <%= f.text_field :description, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">平台分类</label>
          <input type="text" name="shop_category" class="form-control" value="<%= @spu.shop_category.name %>" disabled>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">本店分类</label>
          <% if current_shoper.shop.spu_categories.where("parent_id = 0 OR parent_id IS NULL").count > 0 %>
          <select id="spu_spu_category_id" name="spu[spu_category_id]" class="form-control select">
            <% current_shoper.shop.spu_categories.where("parent_id = 0 OR parent_id IS NULL").each do |spu_category| %>
            <optgroup label="<%= spu_category.name %>">
              <% spu_category.children.each do |child| %>
              <option value="<%= child.id %>" selected="<%= 'selected' if child.id == @spu.spu_category_id %>"><%= child.name %></option>
              <% end %>
            </optgroup>
            <% end %>
          </select>
          <% else %>
          <input type="text" name="no_spu_category" class="form-control" value="没有设置分类" disabled>
          <% end %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">封面<small>（比例1:1）</small></label>
          <div class="custom-file">
            <%= f.file_field :avatar, class: "custom-file-input" %>
            <label class="custom-file-label">选择文件</label>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">最少库存</label>
          <%= f.number_field :min_stock, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">最大库存</label>
          <%= f.number_field :max_stock, class: "form-control" %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">运费模版</label>
          <%= f.select :fare_template_id, current_shoper.shop.fare_templates.map{ |c| [c.name, c.id] }, { include_blank: '请选择模版' }, { class: 'form-control select' } %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">品牌（可不选）</label>
          <%= f.select :brand_id, @spu.shop_category.parent.parent.brands.map{ |c| [c.name, c.id] }, { include_blank: '请选择品牌' }, { class: 'form-control select' } %>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">是否进行促销</label>
          <div class="custom-controls-stacked">
            <label class="custom-control custom-checkbox">
              <%= f.check_box :promotion, class: "custom-control-input" %>
              <span class="custom-control-label">勾选进行促销</span>
            </label>
          </div>
        </div>
      </div>
      <div class="col-md-4">
        <div class="form-group">
          <label class="form-label">能否使用优惠券</label>
          <div class="custom-controls-stacked">
            <label class="custom-control custom-checkbox">
              <%= f.check_box :can_use_coupon, class: "custom-control-input" %>
              <span class="custom-control-label">勾选可使用优惠券</span>
            </label>
          </div>
        </div>
      </div>
      <div class="col-md-12">
        <div class="form-group">
          <label class="form-label">承诺服务</label>
          <div class="selectgroup selectgroup-pills">
            <% ServiceItem.all.each do |service_item| %>
              <label class="selectgroup-item">
                <%= check_box_tag "spu[service_item_ids][]", service_item.id, f.object.service_items.include?(service_item), class: "selectgroup-input" %>
                <span class="selectgroup-button">
                  <%= service_item.name %>
                </span>
              </label>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="card-footer text-right">
    <%= f.submit "保 存", class: "btn btn-primary" %>
  </div>
<% end %>